<%@ page contentType="text/html;charset=UTF-8" language="java"%>

<link rel="stylesheet" media="screen" href="${ctx}/css/Tree.css" />


<div class="container_12 clearfix leading">

	<div class="tabs side grid_6">
		<h5>历史审核</h5>
		<ul class="clearfix">
			<s:if test="#request.audits != null and #request.audits.size() > 1">
				<s:iterator value="#request.audits" status="sta">
					<s:if test="#request.sta.index < #request.audits.size() - 1">
						<li><a class="current" href="#">历史审核#<s:property
									value="#request.sta.index+1" /></a></li>
					</s:if>
				</s:iterator>
			</s:if>
			<s:else>
				<li><a class="current" href="#">没有历史记录</a></li>
			</s:else>
		</ul>
		<section>
			<s:if test="#request.audits != null and #request.audits.size() > 1">
				<s:iterator value="#request.audits" var="audit_process" status="sta">
					<s:if test="#request.sta.index < #request.audits.size() - 1">
						<section style="display: block;" class="clearfix">
							<%--<h4>2012年3月22日</h4>--%>
							<div class="grid_12 alpha">
								<hr>
								<ol class="nostyle">
									<s:iterator value="#request.audit_process" var="a">
										<li>
											<%--TODO:读审核者(审核时登录用户)--%>
											<p class="title">
												${a.auditing.auditTag}
												<button type="reset" class="button" style="float: right">
													<span style="background:url(${ctx}/images/img/accept.png)"
														class="icon">&nbsp;</span>${a.status.name}
												</button>
											</p>
											<p>${a.auditContent}</p>
										</li>
									</s:iterator>
								</ol>
							</div>
						</section>
					</s:if>
				</s:iterator>
			</s:if>
			<s:else>
				<section style="display: none;" class="clearfix">
					<div class="grid_12 alpha">没有历史审核记录</div>
				</section>
			</s:else>
		</section>
	</div>



	<div class="side grid_6">
		<h5>当前审核</h5>
		<div class="accordion">
			<s:if test="#request.audits != null and #request.audits.size() > 0">
				<s:iterator value="#request.audits" var="current_audit_process"
					status="sta">
					<s:if test="#request.sta.index == #request.audits.size() - 1">
						<s:iterator value="#request.current_audit_process" var="ad"
							status="sta4">

							<!-- 审核已通过 -->
							<s:if test="#request.ad.status.toString() == 'pass_audit'">
								<header class="current">
									<%--TODO:审核者--%>
									<h2>
										${ad.auditing.auditTag}
										<button type="reset" class="button"
											style="margin-left: 250px;">
											<span style="background:url(${ctx}/images/img/accept.png)"
												class="icon">&nbsp;</span>已审核
										</button>
									</h2>
								</header>
								<section class="clearfix" style="display: block;">${ad.auditContent}</section>
							</s:if>
							<!--未审核-->
							<s:elseif test="#request.ad.status.toString() == 'wait_audit'">
								<%--TODO:由当前登录用户来审核(这里判断当前登录用户是否可审核)--%>
								<s:if test="#request.sta4.index == -1 or 1==1">
									<header>
										<h2>${ad.auditing.auditTag}</h2>
									</header>
									<section class="clearfix">
										<h6 style="display: none;">待审核</h6>
										<div class="audit_selection_div" id="audit_selection_div_${ad.id}">
                                            <s:if test="#request.canAudit == false">
                                                <h6>非当前审核者</h6>
                                            </s:if>
                                            <s:else>
                                                <h6>审核意见</h6>
                                                <hr>
                                                <textarea rows="5" style="width: 100%; margin-bottom: 10px;" id="audit_content"></textarea>
                                                <input type="radio" name="audit_radio" value="pass_audit"> 同意
                                                <input type="radio" name="audit_radio" value="reject_audit"> 不同意
                                                <button class="button" type="button" onclick="doAudit()">
                                                    <input type="hidden" value="${ad.id}" id="audit_id">
                                                    <span class="icon" style="background:url(${ctx}/images/img/help.png)">&nbsp;</span>确定审核
                                                </button>
                                            </s:else>
										</div>
									</section>
								</s:if>
								<s:else>
									<header>
										<h2>
											${ad.auditing.auditTag}
											<button type="reset" class="button"
												style="margin-left: 250px;">
												<span
													style="background:url(${ctx}/images/img/information.png)"
													class="icon">&nbsp;</span>未审核
											</button>
										</h2>
									</header>
									<section class="clearfix"></section>
								</s:else>
							</s:elseif>

						</s:iterator>
					</s:if>
				</s:iterator>
			</s:if>
			<s:else>
				<header>
					<h2>&nbsp;没有添加审核配置</h2>
				</header>
				<section class="clearfix">&nbsp;</section>
			</s:else>
		</div>
	</div>
</div>

<div class="clear"></div>

<script type="text/javascript" src="js/Tree.js"></script>
<script type="text/javascript" src="${ctx}/js/global_util.js"></script>
<script type="text/javascript">
	$(function() {
		//设置当前审核
		$("div.audit_selection_div").each(function(i) {
			if (i != 0) {
				$(this).prev("h6").show();
				$(this).hide();
			}
		});
	});

	function doAudit() {
		var content = $("#audit_content").val();
		if (checkNull(content)) {
			return;
		}
		//var auditStatus = $("input[type='radio'][@name='audit_radio'][checked]").val();
		var auditStatus = "";
		$("input[type='radio'][name='audit_radio']").each(function() {
			if ($(this).parent(".checked").length == 1) {
				auditStatus = $(this).val();
				return false; //退出each(相当于break, return true相当于continue)
			}
		});

		var auditId = $("#audit_id").val();
		if (auditId == "") {
			return;
		}

		if (auditStatus == null || auditStatus.length == "") {
			//alert("auditStatus="+auditStatus)
			return;
		}

        //构造一个通用的AuditBase对象
        var data = {
            "auditing.id":auditId,
            "organizationId":"${organizationId}",
            "currentAuditType":"${currentAuditType}",
            "auditing.status":auditStatus,
            "auditing.auditContent":content
        };

        if('${currentAuditType}' == "audit_organization"){
            data.organizationId = "${organizationId}";
            data.currentAuditAction = "/organization/audit_list_main.xhtml";
        }else if ('${currentAuditType}' == "audit_job_specification"){
            data.jobSpecificationId = "${jobSpecification.id}";
            data.currentAuditAction = "/rank/job_specification.xhtml?operation=audit";
        }else if ('${currentAuditType}' == "audit_duty_proxy") {
            data.proxyId = "${proxy.id}";
            data.who = "${who}";
            data.currentAuditAction = "/rank/job_specification.xhtml?operation=audit";
            refreshMainContent("${ctx}/duty_proxy/audit.xhtml", data);
            return;
        }else if('${currentAuditType}'=="audit_contract_version"){
            data.versionId = "${versionId}";
            data.currentAuditAction = "/contract/version.xhtml?operation=audit";
        }else if ('${currentAuditType}' == "audit_invite_apply") {
            data.inviteApplyId = "${inviteApply.id}";
            data.currentAuditAction = "/invite/invite_list.xhtml?p=audit";
		} else if('${currentAuditType}'=="audit_contract_sign"){
            data.currentAuditAction = "/contract/conAudit.xhtml";
        } else if('${currentAuditType}'=="audit_transaction_organization"){
            data.currentAuditAction = "/transaction/organization_main.xhtml";
        } else if('${currentAuditType}'=="audit_transaction_other"){
            if("${type}" == "promotion"){
                data.currentAuditAction = "/transaction/promotion_main.xhtml";
            }else{
                data.currentAuditAction = "/transaction/demotion_main.xhtml";
            }
        }else if('${currentAuditType}'=="audit_financial_report_form"){
            data.currentAuditAction = "/sign/financial-report-form.xhtml";
        }else if('${currentAuditType}'=="audit_financial_payment_apply_form"){
            data.currentAuditAction = "/sign/financial-payment-apply-form.xhtml";
        }else if('${currentAuditType}'=="audit_financial_in_bill_form"){
            data.currentAuditAction = "/sign/financial-in-bill-form.xhtml";
        }else if('${currentAuditType}'=="audit_administration_evection_apply_form"){
            data.currentAuditAction = "/sign/administration-evection-apply-form.xhtml";
        }else if('${currentAuditType}'=="audit_administration_evection_report_form"){
            data.currentAuditAction = "/sign/administration-evection-report-form.xhtml";
        }else if('${currentAuditType}'=="audit_administration_evection_cost_report_form"){
            data.currentAuditAction = "/sign/administration-evection-cost-apply-form.xhtml";
        }else if('${currentAuditType}'=="audit_administration_out_apply_form"){
            data.currentAuditAction = "/sign/administration-out-apply-form.xhtml";
        }else if('${currentAuditType}'=="audit_administration_leave_apply_form"){
            data.currentAuditAction = "/sign/administration-leave-apply-form.xhtml";
        }else if('${currentAuditType}'=="audit_leave_office"){
            data.currentAuditAction = "/leave/apply-audit-main.xhtml";
        }else if('${currentAuditType}'=="audit_train_plan"){
            data.currentAuditAction = "/train/plan_audit_main.xhtml";
        }else if('${currentAuditType}'=="audit_train_plan_outing"){
            data.currentAuditAction = "/train/outing_audit_main.xhtml";
        }else if('${currentAuditType}'=="audit_exam_award"){
            data.currentAuditAction = "/exam/award_audit_main.xhtml";
        }

		//for(var p in data){alert(p+"----"+data[p])}
		refreshMainContent("${ctx}/authority/audit-base.xhtml", data);
	}
</script>